package com.sxt.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sxt.sys.domain.Topic;
import com.sxt.sys.domain.User;
import com.sxt.sys.mapper.TopicMapper;
import com.sxt.sys.mapper.UserMapper;
import com.sxt.sys.service.TopicService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxt.sys.utils.DataGridView;
import com.sxt.sys.vo.TopicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cr
 * @since 2019-04-29
 */
@Service
public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements TopicService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private TopicMapper topicMapper;

    @Override
    public User queryOne(String loginname, String password) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("loginname",loginname);
        queryWrapper.eq("pwd",password);

        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    @Override
    public DataGridView queryAll(TopicVo topicVo) {
        Page<Object> objects = PageHelper.startPage(topicVo.getPage(), topicVo.getLimit());

        List<TopicVo> top = topicMapper.queryAll(topicVo);
        return new DataGridView(objects.getTotal(),top);
    }

    @Override
    public Integer insert(TopicVo topicVo) {

        return topicMapper.insert(topicVo);
    }
}
